package com.taoyusen.jpf.server.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.taoyusen.jpf.dao.IUserInfoDao;
import com.taoyusen.jpf.dao.pojo.TSysUserinfo;
import com.taoyusen.jpf.server.IUserInfoServer;
import com.taoyusen.jpf.server.dto.UserInfoDto;

public class UserInfoServerImpl implements IUserInfoServer
{

	private IUserInfoDao userInfoDao;

	public void setUserInfoDao(IUserInfoDao userInfoDao) 
	{
		this.userInfoDao = userInfoDao;
	}
	
	
	public List<UserInfoDto> getAllUserInfoDto()throws Exception
	{
		List<UserInfoDto> userDtoList = new ArrayList<UserInfoDto>();
		
		List<TSysUserinfo> resultList =  this.userInfoDao.getAllObject();
		if(resultList.size() > 0)
		{
			for (int i = 0; i < resultList.size(); i++)
			{
				UserInfoDto userInfoDto = new UserInfoDto();
				TSysUserinfo userInfo = (TSysUserinfo)resultList.get(i);
				userInfoDto.copyUserInfoDto(userInfoDto,userInfo);
				
				userDtoList.add(userInfoDto);
			}
		}
		
		return userDtoList;
	}


	public List<UserInfoDto> getUserInfoByMap(Map<String, Object> userMap) throws Exception
	{
		List<UserInfoDto> dtoList = new ArrayList<UserInfoDto>();
		
		List reslutList = this.userInfoDao.getUserInfoByMap(userMap);
		if(reslutList.size() > 0)
		{
			for (int i = 0; i < reslutList.size(); i++)
			{
				UserInfoDto userInfoDto = new UserInfoDto();
				TSysUserinfo user = (TSysUserinfo)reslutList.get(i);
				userInfoDto.copyUserInfoDto(userInfoDto, user);
				dtoList.add(userInfoDto);
			}
		}
		
		return dtoList;
	}


	public List<UserInfoDto> getUserInfoByUserName(String userName) throws Exception 
	{
		List<UserInfoDto> dtoList = new ArrayList<UserInfoDto>();
		List reslutList = this.userInfoDao.getUserInfoByUserName(userName);
		
		if(reslutList.size() > 0)
		{
			for (int i = 0; i < reslutList.size(); i++)
			{
				UserInfoDto userInfoDto = new UserInfoDto();
				TSysUserinfo user = (TSysUserinfo)reslutList.get(i);
				userInfoDto.copyUserInfoDto(userInfoDto, user);
				dtoList.add(userInfoDto);
			}
		}
		
		return dtoList;
	}


	public boolean deleteUser(String userId) throws Exception 
	{
		boolean success = false;
		
		TSysUserinfo userInfo = this.userInfoDao.getObjectById(userId);
		if(userInfo != null)
		{
			success = this.userInfoDao.delete(userInfo);
		}
		
		return success;
	}
	
}
